package com.example.program.controller;

import com.example.program.anno.LOg;
import com.example.program.pojo.Dept;
import com.example.program.pojo.Result;
import com.example.program.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list() {
        List<Dept> deptList = deptService.list();
        System.out.println("1");
        return Result.success(deptList);
    }
    @LOg
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id)throws Exception
    {
        deptService.delete(id);
        return Result.success();

    }
    @LOg
    @PostMapping
    public Result add(@RequestBody Dept dept)
    {

        deptService.add(dept);
        return Result.success();
    }
}
